<template>
  <div class="mk-cases">
    <div class="swiper-container swiper1">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item) in bannerLists">
          <img :src="item.banner_pic" alt>
        </div>
      </div>
      <div class="swiper-pagination"></div>
    </div>
    <div class="bread-nav">
      <div class="nav-box">
        <span>您的位置：</span>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">网站首页</el-breadcrumb-item>
          <el-breadcrumb-item>案例展示</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    <div class="content">
      <h3 class="title">案例展示</h3>
      <h4 class="sub-title">Case</h4>
      <div class="cases">
        <div class="case-item" v-for="(item,index) in cases">
          <div class="item-block" v-show="(index+1)%2!==0">
            <div class="left">
              <img :src="'https://cdn1-open.mokyun.com/'+item.case_pic" alt>
            </div>
            <div class="right">
              <h3 class="title">{{item.case_name}}</h3>
              <p class="text" v-html="item.case_desc"></p>
              <div class="more" @click="goCaseDetails(item.id)">了解更多</div>
            </div>
          </div>
          <div class="item-block">
            <div class="left">
              <h3 class="title">{{item.case_name}}</h3>
              <p class="text" v-html="item.case_desc"></p>
              <div class="more" @click="goCaseDetails(item.id)">了解更多</div>
            </div>
            <div class="right">
              <img :src="'https://cdn1-open.mokyun.com/'+item.case_pic" alt>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import getData from "../api/getInfo";

export default {
  data() {
    return {
      bannerLists: [],
      cases: []
    };
  },
  mounted() {
    this.getBanner();
    this.getCases();
  },
  methods: {
    initSwiper() {
      let mySwiper = new Swiper(".swiper1", {
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        },
        loop: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
           bulletActiveClass: "my-bullet-active"
        },
        observer: true
      });
    },
    //获取banner图
    getBanner() {
      getData
        .getBanner()
        .then(res => {
          let tempArr = [];
          res.data.forEach((val, index) => {
            if (val.type == 3) {
              val.banner_pic = `${getData.url}${val.banner_pic}`;
              tempArr.push(val);
            }
          });
          this.bannerLists = tempArr;
          this.$nextTick(() => {
            // 下一个UI帧再初始化swiper
            this.initSwiper();
          });
        })
        .catch(e => {
          console.log(e);
        });
    },
    //获取案例展示
    getCases() {
      getData
        .getCases()
        .then(res => {
          this.cases = res.data;
        })
        .catch(e => {
          console.log(e);
        });
    },
    //案例详情
    goCaseDetails(case_id) {
      this.$router.push({
        path: `/caseDetails/${case_id}`
      });
    }
  }
};
</script>
<style scoped lang="scss">
.swiper-container {
  height: 505px;
  width: 100%;
}
/deep/.bread-nav {
  width: 100%;
  height: 52px;
  background: #f6f6f6;
  .nav-box {
    width: 1200px;
    height: 52px;
    line-height: 52px;
    margin: 0 auto;
    display: flex;
    span,
    a {
      font-size: 14px;
      color: #9d9d9d;
    }
    .current {
      color: #96ce54;
    }
    .el-breadcrumb {
      line-height: 52px;
    }
    .el-breadcrumb__inner {
      color: #96ce54;
    }
    .el-breadcrumb__inner.is-link {
      color: #9d9d9d;
      font-weight: normal;
    }
  }
}
.content {
  padding-bottom: 100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  .title {
    font-size: 36px;
    color: #323232;
    margin: 76px 0 6px 0;
  }
  .sub-title {
    font-size: 18px;
    color: #b8b7b7;
  }
  .cases {
    width: 100%;
    display: flex;
    flex-direction: column;
    margin-top: 46px;
    .case-item {
      width: 100%;
      height: 415px;
      .item-block {
        width: 1056px;
        height: 100%;
        margin: 0 auto;
        display: flex;
        align-items: center;
        .left {
          width: 483px;
          height: 305px;
          margin-right: 90px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .right {
          width: 483px;
          height: 305px;
          display: flex;
          box-sizing: border-box;
          flex-direction: column;
          align-items: center;
          .title {
            font-size: 16px;
            color: #323232;
            margin-top: 50px;
            margin-bottom: 33px;
          }
          .text {
            font-size: 16px;
            color: #999;
            text-align: justify;
            line-height: 24px;
          }
          .more {
            width: 148px;
            height: 42px;
            text-align: center;
            line-height: 42px;
            border: solid 1px #96ce54;
            color: #96ce54;
            font-size: 16px;
            margin-top: 26px;
            cursor: pointer;
          }
          .more:hover {
            color: #fff;
            background: #96ce54;
          }
        }
      }
    }
    .case-item:nth-child(2n) {
      background: #fafafa;
      .left {
        width: 483px;
        height: 305px;
        display: flex;
        box-sizing: border-box;
        flex-direction: column;
        align-items: center;
        margin-right: 90px;
        .title {
          font-size: 16px;
          color: #323232;
          margin-top: 50px;
          margin-bottom: 33px;
        }
        .text {
          font-size: 16px;
          color: #999;
          text-align: justify;
          line-height: 24px;
        }
        .more {
          width: 148px;
          height: 42px;
          text-align: center;
          line-height: 42px;
          border: solid 1px #96ce54;
          color: #96ce54;
          font-size: 16px;
          margin-top: 26px;
          cursor: pointer;
        }
        .more:hover {
          color: #fff;
          background: #96ce54;
        }
      }
      .right {
        width: 483px;
        height: 305px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>


